﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using BLL;
namespace 健身房管理
{
    public partial class Umessage : UserControl
    {
        huiyuanBLL hyb = new huiyuanBLL();
        public Umessage()
        {
            InitializeComponent();
        }

        private void guna2Button1_Click(object sender, EventArgs e)
        {
            MailMessage msg = new MailMessage();
            string connectpath = contenttxt.Text;
            string mailpath = mailtxt.Text;       //发送人QQ号
            string mailnextpath = comboBox3.Text; //发送人选择的邮箱
            string recipien = recipienttxt.Text;  //收件人QQ号
            string recipiennextpath = comboBox1.Text; //收件人选择的邮箱
            string titlepath = titletxt.Text; //文章的标题
            msg.From = new MailAddress(mailpath.ToString() + mailnextpath); //   发送的邮件地址（主机）
            msg.Body = connectpath;
            //msg.Sender = new MailAddress("");
            msg.To.Add(recipien.ToString() + recipiennextpath);      //要接受的邮件地址
            msg.Subject = titlepath;


            msg.IsBodyHtml = true;                         //邮件内容默认是纯文本！如果指定html内容，需要使用isbodyHtml
            SmtpClient sc = new SmtpClient();
            sc.Host = "smtp.qq.com";                 //这个不一定是163，看你的主机的邮箱型号，还可以是smtp.qq.com, smtp.126.com , smtp.yahoo.com 等等
            sc.Port = 25;
            NetworkCredential nc = new NetworkCredential();
            nc.UserName = "2244727152@qq.com";       //主机的邮箱名称
            nc.Password = "bljusvepoqiidjca";     //主机的邮箱密码
            sc.Credentials = nc;

            if (this.fujietxt.Text != "")
            {
                Attachment att = new Attachment(this.fujietxt.Text);
                msg.Attachments.Add(att);
            }
            else
            {
            }
            sc.Send(msg);
            MessageBox.Show("发送成功！");
        }
        private OpenFileDialog openFileDialog = new OpenFileDialog();
        private void guna2Button2_Click(object sender, EventArgs e)
        {
            if (this.openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.fujietxt.Text = this.openFileDialog.FileName;           //上传附件，打开对话框，得到客户端的文件
            }
        }

        private void Umessage_Load(object sender, EventArgs e)
        {
            jiazmail();
        }

        public void jiazmail()
        {
            this.guna2DataGridView1.AutoGenerateColumns = false;
            this.guna2DataGridView1.DataSource = hyb.hydgvshow1();         
        }
    }
}
